/*!
 * @Author: CPS
 * @email: 373704015@qq.com
 * @Date: 2020-09-17 17:51:59
 * @Last Modified by: CPS
 * @Last Modified time: 2020-09-24 18:35:38
 * @Projectname Electron-fileWatcher
 * @file_path Z:\CPS\IDE\SublimeText\3176x32前端\Data\Packages\testt\Plugins\pug\html2pug.js
 * @Filename html2pug.js
 */
"use strict";
const html2pug = require("html2pug");
const html2jade = require("html2jade");
const pugBeauty = require("./pugBeauty.js");
const defaultOptions = require("./html2pug.defaultOptions.js");

// 处理函数
function format(tar, options) {
  let res;
  try {
    if (options) Object.assign(defaultOptions, options);
    html2jade.convertHtml(tar, defaultOptions, function (err, jade) {
      res = pugBeauty(jade);
      return res;
    });
    // res = pugBeauty(html2pug(tar));
  } catch (e) {
    // statements
    return console.log(e);
  }
  return res;
}

// 测试环境
if (process.mainModule.filename === __filename) {
  // 测试代码
  let testStr = `
  <el-aside id="asideNav">
    <h5>自定义颜色</h5>
    <!-- 导航容器 -->
    <el-menu
      default-active="1"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#242424"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <!-- 一级菜单1 -->
      <el-menu-item index="1">
        <!-- 一级icon -->
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>首页</span>
        </template>
      </el-menu-item>

      <!-- 一级菜单2 -->
      <el-menu-item index="2">
        <!-- 一级icon -->
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>产品管理</span>
        </template>
      </el-menu-item>

      <!-- 一级菜单2 -->
      <el-menu-item index="3">
        <!-- 一级icon -->
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>上传产品</span>
        </template>
      </el-menu-item>
    </el-menu>
  </el-aside>
`;
  console.log(format(testStr));

  //退出
  process.exit();
}

// 导出调用
module.exports = format;
